Print Hello World in C#

If you have ever learned programming language, then you know that they are all "Hello, world!" Come on, for example, start with, and who are we to break such a good tradition? Start the scene in C # Express (presented in the previous chapter), and choose File -> New Project ... From the project dialog, select the console application. This is the most basic application type on the Windows system, but do not worry, we will not be here for a long time. Once you click OK, Visual C # Express creates a new project for you, which contains a file called program.cs. This is where all the fun is, and it should look something like this:


using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
} 

Indeed, all these rows do not really get anything, or at least it may seem like trying to run an apple by pressing F5 on your keyboard, this view will compile and execute C # Express on your keyboard. , But as you will see, it does not do much, you will probably see a black window launch and close again. This is because our application does not do anything in the next chapter yet, we will look through these lines to see what they are all, but now, if we really want to see some results, then show us that all of us Know about and add some lines to get some output. In the last set of {}, add these lines:


Console.WriteLine("Hello, world!");
Console.ReadLine();

The code of your first application should now look like this:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
            Console.ReadLine();
        }
    }
}

Once again, hit F5 to run it, and you'll actually see a black window, and our greetings for the world are also looking good, so we added two lines, but what did they do? One of the good things about the C # and NAT framework is the fact that many codes are understood by untrained eyes, which have been explained by this example.

The first line uses the console square to create a line of text, and the second reads a line of text from the console. Read? Why? Actually, it's a bit of a trick, because without it, this application only closes the window and anyone with the output can see it.

The readline command asks the user to wait for input from the application, and as you will see, the console window now allows you to enter text. Press Enter to close it Congratulations, you have just created your first C # application! For more information about what's really happening, read the next chapter.